# -*- coding: utf-8 -*-
# @Time    : 2022/1/6
# @Author  : yuanxi

from airtest.core.api import *
from basic.device.Android import Android

class wsPage(Android):
    wsListName = "com.cloudbae.lovenanning:id/digital_name"
    # wsListNum = "com.cloudbae.lovenanning:id/digital_num"
    content="身份电子信息45052**********345"
    wsCardView = "com.cloudbae.lovenanning:id/card_view"
    secCardTitle = "com.cloudbae.lovenanning:id/tv_title"
    @classmethod
    def getWsList(self):
        print("获取数字证照列表")
        sleep(2)
        listCard = self.poco(self.wsListName)
        print("获取到的数字证照列表卡片数：", len(listCard))
        listName = []
        for i in range(0, len(listCard)):
            listName.append(listCard[i].get_text())
        print("-------")
        print("数字证照列表", listName)
        return listName

    # @classmethod
    # def getWsNum(self):
    #     print("获取数字证照身份证号")
    #     NumList = self.poco(self.wsListNum).wait(2)
    #     # 只获取前三个卡片的身份证号
    #     for i in range(0, 3):
    #         # Num.append(NumList[i].get_text())
    #         Num = NumList[i].get_text()
    #         print("首页身份证号:", Num)
    #         if Num != "45052**********345":
    #             return False
    #     return True

    @classmethod
    def getWsNum(self):
        print("获取数字证照身份证号")
        NumList = self.poco(self.content).wait(2)
        # 只获取前三个卡片的身份证号
        if NumList != "身份电子信息45052**********345":
            return True
        return False


    @classmethod
    def clickIdCard(self):
        print("点击身份电子信息卡片")
        if exists(Template(r"2.png")):
            touch(Template(r"2.png"))
            print("点击成功")
        else:
            print("未找到目标图片")

    @classmethod
    def getCardName(self):
        sleep(2)
        print("电子身份证")
        name = self.poco(text="*远婷").wait(2)
        print("name:", name)
        if name.exists():
            return True

    @classmethod
    def clickSecCard(self):
        print("点击电子社保卡卡片")
        if exists(Template(r"D:\desktop\git\YBBAirTestLab\1.png")):
            touch(Template(r"D:\desktop\git\YBBAirTestLab\1.png"))
            print("点击成功")
        else:
            print("未找到目标图片")

    @classmethod
    def getSecCard(self):
        sleep(5)
        secCard = self.poco(self.secCardTitle).get_text()
        sleep(3)
        print("电子社保卡页面:", secCard)
        return secCard

    @classmethod
    def clickAccCard(self):
        print("点击公积金卡片")
        self.poco(name=self.wsListName, text="公积金").click()

    @classmethod
    def getAccCard(self):
        print("公积金")
        sleep(5)
        accCard = self.poco(text="*远婷").wait(2)
        print("公积金页面：", accCard)
        if accCard.exists():
            return True


